﻿namespace com.oakwoodsys.ConsultantCare
{
    using System.Linq;

    using com.oakwoodsys.ConsultantCareDao;
    using com.oakwoodsys.Extensions.SymbolExtensions;
    using com.oakwoodsys.SharePoint;

    using Microsoft.SharePoint;

    using ReferenceObject = ConsultantCareDao.Consultant;

    public class Consultant_Definition_SiteLevel : CustomBaseDefinition
    {
        #region Fields

        const string SITECOLUMNS = "Consultant.xml";

        #endregion Fields

        #region Constructors

        public Consultant_Definition_SiteLevel( SPFeatureReceiverProperties properties )
            : base(properties)
        {
        }

        ~Consultant_Definition_SiteLevel( )
        {
            Dispose( false );
        }

        #endregion Constructors

        #region Methods

        public override void Create( )
        {
            base.Create( );
            CreateSiteColumns( GetFieldDefinitionsAsXml( SITECOLUMNS ) );
            CreateContentType( getContentTypeDefn( ) );
        }

        public override void Delete( )
        {
            base.Delete( );
            DeleteContentType( getContentTypeDefn( ) );
            DeleteSiteColumns( GetFieldDefinitionsAsXml( SITECOLUMNS ) );
        }

        ContentTypeDefn getContentTypeDefn( )
        {
            ReferenceObject c = null;
            return new ContentTypeDefn
            {
                Name = Item.GetContentTypeName<ReferenceObject>( ),
                ContentTypeId = Item.GetContentTypeId<ReferenceObject>( ),
                Group = "Oakwood-Consultant Care",
                Description = "Defines a consultant.",
                Fields = new FieldDefn[ ]
                {
                    new FieldDefn{ Name = Item.GetColumnName<ReferenceObject>( c.GetPropertySymbol( o=> o.Note ))},
                    new FieldDefn{ Name = Item.GetColumnName<ReferenceObject>( c.GetPropertySymbol( o=> o.Type )), Required = true },
                    new FieldDefn{ Name = Item.GetColumnName<ReferenceObject>( c.GetPropertySymbol( o=> o.RecruiterId )), Required = true },
                    new FieldDefn{ Name = Item.GetColumnName<ReferenceObject>( c.GetPropertySymbol( o=> o.StartDate )), Required = true },
                    new FieldDefn{ Name = Item.GetColumnName<ReferenceObject>( c.GetPropertySymbol( o=> o.ClientName )), Required = true },
                    new FieldDefn{ Name = Item.GetColumnName<ReferenceObject>( c.GetPropertySymbol( o=> o.DOB ))},
                    new FieldDefn{ Name = Item.GetColumnName<ReferenceObject>( c.GetPropertySymbol( o=> o.EmailAddress )), Required = true },
                    new FieldDefn{ Name = Item.GetColumnName<ReferenceObject>( c.GetPropertySymbol( o=> o.TelMobile ))},
                    new FieldDefn{ Name = Item.GetColumnName<ReferenceObject>( c.GetPropertySymbol( o=> o.TelOther ))},
                    new FieldDefn{ Name = Item.GetColumnName<ReferenceObject>( c.GetPropertySymbol( o=> o.Active ))},
                }.Distinct( ).ToList( )
            };
        }

        #endregion Methods
    }
}